package com.zcm.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zcm.dao.CommodityDao;
import com.zcm.entity.address;
import com.zcm.entity.commodity;
import com.zcm.service.CommodityService;
import com.zcm.service.UserService;

/**
 * Servlet implementation class DoUpdateAddress
 */
@WebServlet("/DoUpdateAddress")
public class DoUpdateAddress extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DoUpdateAddress() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		UserService us = new UserService();
		address ad = new address();
		int userid = Integer.parseInt(request.getParameter("userid")); 
		String name = request.getParameter("name");
		String province = request.getParameter("province");
		String phonenum = request.getParameter("phonenum");
		String zone = request.getParameter("zone");
		String zone2 = request.getParameter("zone2");
		String stree = request.getParameter("stree");
		String zipcode = request.getParameter("zipcode");
		String alabel = request.getParameter("alabel");
		int id = Integer.parseInt(request.getParameter("id")); 
		ad.setUserid(userid);
		ad.setName(name);
		ad.setProvince(province);
		ad.setPhonenum(phonenum);
		ad.setZone(zone);
		ad.setZone2(zone2);
		ad.setStree(stree);
		ad.setZipcode(zipcode);
		ad.setAlabel(alabel);
		ad.setId(id);
		us.UpdateAddress(ad);
		
		CommodityService cs = new CommodityService();
		List<commodity> lc = new ArrayList<>();
		lc = cs.SelectUserShoppingCart(userid);
		request.setAttribute("lc", lc);
		
		List<commodity> c = new ArrayList<>();
		c = cs.SelectUserShoppingCart(userid);
		request.setAttribute("c", c);
		List list = new ArrayList<>();
		list = us.SelectAddressByUserID(userid);
		request.setAttribute("list", list);
		request.setAttribute("userid",userid);
		request.getRequestDispatcher("/Pay.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
